package com.sunday.haowushop.ui.order;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sunday.common.base.BaseActivity;
import com.sunday.haowushop.R;
import com.sunday.haowushop.entity.OpenShopOrder;

import java.math.RoundingMode;

import butterknife.Bind;
import butterknife.ButterKnife;



/**
 * Created by 刘涛 on 2017/8/4.
 */

public class ShopGiftOrderDetailActivity extends BaseActivity {


    @Bind(R.id.title_view)
    TextView titleView;
    @Bind(R.id.order_status)
    TextView orderStatus;
    @Bind(R.id.user_name)
    TextView userName;
    @Bind(R.id.user_addr)
    TextView userAddr;
    @Bind(R.id.product_image)
    ImageView productImage;
    @Bind(R.id.product_name)
    TextView productName;
    @Bind(R.id.product_price)
    TextView productPrice;
    @Bind(R.id.valid_time)
    TextView validTime;
    @Bind(R.id.product_spec)
    TextView productSpec;
    @Bind(R.id.product_num)
    TextView productNum;
    @Bind(R.id.pro_layout)
    RelativeLayout proLayout;
    @Bind(R.id.express_money)
    TextView expressMoney;
    @Bind(R.id.total_money)
    TextView totalMoney;
    @Bind(R.id.order_no)
    TextView orderNo;
    @Bind(R.id.order_create_time)
    TextView orderCreateTime;
    @Bind(R.id.order_pay_time)
    TextView orderPayTime;
    @Bind(R.id.order_send_time)
    TextView orderSendTime;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shop_order_detail);
        ButterKnife.bind(this);
        titleView.setText("订单详情");
        OpenShopOrder order = (OpenShopOrder) getIntent().getSerializableExtra("shopOrder");
        if (order != null) {
            updateView(order);
        }
    }

    private void updateView(OpenShopOrder shopOrder) {
        if (shopOrder.getStatus() == 1) {
            //待发货
            orderStatus.setText("待发货");
        } else if (shopOrder.getStatus() == 4) {
            //已完成
            orderStatus.setText("已完成");
        } else {
            orderStatus.setText("待收货");
        }

        userName.setText(String.format("%1$s  %2$s", shopOrder.getName(), shopOrder.getMobile()));
        userAddr.setText(shopOrder.getAddress());
        validTime.setText("有效期" + shopOrder.getYear());
        productSpec.setText("规格:" + shopOrder.getElements());
        productName.setText(shopOrder.getTitle());
        if (!TextUtils.isEmpty(shopOrder.getImage()))
            Glide.with(mContext)
                    .load(shopOrder.getImage())
                    .into(productImage);
        productPrice.setText(String.format("¥%s", shopOrder.getTotalFee().setScale(2, RoundingMode.HALF_UP)));
        expressMoney.setText("免运费");
        totalMoney.setText(String.format("%s元", shopOrder.getTotalFee().setScale(2, RoundingMode.HALF_UP)));
        orderNo.setText(shopOrder.getOrderNo());
        orderCreateTime.setText(shopOrder.getCreateTime());
        orderPayTime.setText(shopOrder.getPayTime());
        orderSendTime.setText(shopOrder.getSendTime());
    }
}
